﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class PROVIDERDAO
    {
        public bool Update_info(PROVIDER prv)
        {
            
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            PROVIDER provider = db.PROVIDERs.Single(p => p.IDPROVIDER == prv.IDPROVIDER);
            provider.ADDRESS = prv.ADDRESS;
            provider.INTRODUCE_COMPANY = prv.INTRODUCE_COMPANY;
            provider.MAP = prv.MAP;
            provider.NAME = prv.NAME;
            provider.PHONE = prv.PHONE;
            db.SubmitChanges();
            return true;
        }
        public static PROVIDER Get_Info(String Username)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            PROVIDER provider = db.PROVIDERs.Single(p => p.NAME  == Username );
            return provider;

        }
        public static PROVIDER Get_Info(int id)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            PROVIDER provider = db.PROVIDERs.Single(p => p.IDPROVIDER == id);
            return provider;

        }
       /* public static ORDER[] Getlist_orderby_provider(int idprv)
        {
            
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            var orderlist = from o in db.ORDERs
                            where o.IDPRODUCT == (from p in db.PRODUCTs
                                                 where p.IDPROVIDER == idprv
                                                 select p.IDPRODUCT)
                            select o;
            return orderlist.ToArray<ORDER>();
        }*/
        public static List<PROVIDER> Getlist()
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            var list = from p in db.PROVIDERs
                       select p;
            return list.ToList<PROVIDER>();
        }

        public static bool Delete(int idprovider)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            PROVIDER provider = db.PROVIDERs.Single(p=> p.IDPROVIDER == idprovider);
            db.PROVIDERs.DeleteOnSubmit(provider);
            db.SubmitChanges();
            return true;
        }

        public static bool Add(PROVIDER provider)
        {
            DataClassesNHOMMUADataContext db = new DataClassesNHOMMUADataContext();
            db.PROVIDERs.InsertOnSubmit(provider);
            db.SubmitChanges();
            return true;
        }
    }
}
